/** 新账号数据 */
var combobox = require("./base/combobox.js");
cc.Class({
    extends: cc.Component,

    properties: {
        /** 背景图片 */
        sp_bg:cc.Sprite,
        /** 英雄名 */
        eb_heroname:cc.EditBox,
        /** 城镇名 */
        eb_cityname:cc.EditBox,
        /** 性别 */
        tg_sex:cc.ToggleContainer,
        /** 性别文字 */
        _sex:cc.String,
        /** 信仰 */
        cb_gods:combobox,
        /** 种族 */
        cb_race:combobox,
        /** 区域 */
        cb_area:combobox,
        /** 种族文字 */
        sp_race:cc.Sprite,
        /** 头像图片 */
        sp_img:cc.Sprite,
        /** 新用户背景 */
        nd_hero:cc.Node,
        /** 创建按钮 */
        bt_create:cc.Button,
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad () {
        this.sp_bg.spriteFrame = new cc.SpriteFrame(App.path+"gods/1.jpg");
        this.sp_race.spriteFrame = new cc.SpriteFrame(App.path+"gods/r1.png");
        this._sex = "m";
        this.sp_img.spriteFrame = new cc.SpriteFrame(App.path+"hero/"+this._sex+"_1_1.jpg");

        this.nd_hero.on("combo", function(ev){
            //console.log("xxxx", ev.target.name);
            if(ev.target.name == "gods"){
                this.sp_bg.spriteFrame = new cc.SpriteFrame(App.path+"gods/"+(this.cb_gods.selIndex+1)+".jpg");
            }else if(ev.target.name == "race"){
                this.sp_race.spriteFrame = new cc.SpriteFrame(App.path+"gods/r"+(this.cb_race.selIndex+1)+".png");
                this.sp_img.spriteFrame = new cc.SpriteFrame(App.path+"hero/"+this._sex+"_"+(this.cb_race.selIndex+1)+"_1.jpg");
            }else{
                this.sp_img.spriteFrame = new cc.SpriteFrame(App.path+"hero/"+this._sex+"_"+(this.cb_race.selIndex+1)+"_1.jpg");
            }
        }, this);

        this.bt_create.node.on(cc.Node.EventType.TOUCH_END, function(ev){
            App.net.send([0,3,{uname:this.eb_heroname.string,hname:this.eb_heroname.string,cname:this.eb_cityname.string,"gods":this.cb_gods.selIndex+1,"race":this.cb_race.selIndex+1,"hpic":this._sex+"_"+(this.cb_race.selIndex+1),"barea":this.cb_area.selIndex}])
        }, this);
    },

    start () {

    },

    // update (dt) {},

    tgClick(){
        if(this.tg_sex.toggleItems[0].isChecked){
            this._sex = "m";
        }else{
            this._sex = "w";
        }
        console.log("tg_sex", this._sex);
        this.sp_img.spriteFrame = new cc.SpriteFrame(App.path+"hero/"+this._sex+"_"+(this.cb_race.selIndex+1)+"_1.jpg");        
    }
});
